<!--回弹业务数据字典---回弹仪器设备管理---查看-->
<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left">
          <el-radio-group
            v-model="radio"
            size="small"
            @change="modelType($event)"
          >
            <el-radio-button label="待办"></el-radio-button>
            <el-radio-button label="已办"></el-radio-button>
            <!-- #2b5a9d -->
          </el-radio-group>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="small"
              @click="yj_searchForm(getList)"
            ></el-button>

            <el-button
              type="primary"
              v-if="yj_view"
              icon="el-icon-search"
              size="small"
              @click="editText(fId)"
            >
              查看
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0' && yj_edit == true"
              @click="edit('编辑')"
            >
              编辑
            </el-button>

            <el-button
              type="primary"
              v-if="getList.modelType == '0' && yj_export == true"
              icon="el-icon-search"
              size="small"
              @click="Print()"
            >
              导出
            </el-button>
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="loading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @ClickOnLine="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          v-if="navigatepageNums > 1"
          :info="queryCriteriaData"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
      <!--闭合 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 20px">
              <div class="baseTitle">基本信息</div>
              <div class="publicForm" style="height: 110px">
                <publicForm
                  ref="publicForm0"
                  lableWidth="96px"
                  :formObj="formObj"
                  :formData="formData"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>
              <div class="baseTitle" style="margin-top: 8px">处理情况</div>
              <el-collapse v-model="activeNames" @change="changeCollapse">
                <el-collapse-item name="0">
                  <template slot="title">
                    <div>
                      <img
                        style="vertical-align: middle"
                        src="@/assets/img/Supervision/com_flg.png"
                        alt=""
                      />
                      <span style="margin-left: 8px">闭合申请单</span>
                    </div>
                  </template>
                  <div style="height: 160px; margin-top: 3px">
                    <publicForm
                      ref="publicForm0"
                      lableWidth="96px"
                      :formObj="handleObj"
                      :formData="handleData"
                      :timestamp="handleData.fHandlefile"
                      :fileList="fSourcefileList"
                      @delteFile="delteFile"
                    >
                    </publicForm>
                  </div>
                </el-collapse-item>

                <el-collapse-item name="1">
                  <template slot="title">
                    <div>
                      <img
                        style="vertical-align: middle"
                        src="@/assets/img/Supervision/com_flg.png"
                        alt=""
                      />
                      <span style="margin-left: 8px">一级审核</span>
                    </div>
                  </template>
                  <div style="height: 110px; margin-top: 3px">
                    <publicForm
                      ref="publicForm1"
                      lableWidth="96px"
                      :formObj="processObj"
                      :formData="handleData"
                      :timestamp="handleData.fHandlefile"
                      :fileList="fSourcefileList"
                      @delteFile="delteFile"
                    >
                    </publicForm>
                  </div>
                </el-collapse-item>
                <el-collapse-item name="2">
                  <template slot="title">
                    <div>
                      <img
                        style="vertical-align: middle"
                        src="@/assets/img/Supervision/com_flg.png"
                        alt=""
                      />
                      <span style="margin-left: 8px">二级审核</span>
                    </div>
                  </template>
                  <div style="height: 110px; margin-top: 3px">
                    <publicForm
                      ref="publicForm2"
                      lableWidth="96px"
                      :formObj="examineObjs"
                      :formData="handleData"
                      :timestamp="handleData.fHandlefile"
                      :fileList="fSourcefileList"
                      @delteFile="delteFile"
                    >
                    </publicForm>
                  </div>
                </el-collapse-item>
              </el-collapse>

              <div style="height: 50px"></div>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button type="primary" @click="yj_saveForm()"> 保存 </el-button>

            <el-button type="warning" @click="dialogEditVisible = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getQualityDutyStationLists, //列表
  getQualityDutyStationByFid, //详情
  saveQualityDutyStation, //保存
  // getBaseDepartmentUser, //调人员
} from "@/api/request.js";
import TableData from "@/components/stationProductionPage/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项

export default {
  inject: ["reload"],
  name: "unqualifiedReportText",
  data() {
    return {
      name: "unqualifiedReportText",
      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页
      yj_edit: null,
      yj_view: null,
      yj_export: null,
      radio: "待办",
      // 列表
      getList: {
        fCompanyid: "", // 查询条件项目名称id
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
        userId: "", // 查询待办或已办时传 列表页查询不传
        modelType: "0", // 0-待办 1-已办 传2 表示列表页查询
        fQualitygridtype: "", // 上方查询条件工程网格
        fQualitygridclass: "", // 上方查询条件质量网格
        keyWord: "", // 责任人
      },
      fId: null, //当前行数据fId
      loading: false, //列表转载
      table_config: formJs.table_config,
      tableData: [], //表格列表数据列表
      // 列表

      // 弹框
      timeYMD: null, //当前日期
      btnShow: true,
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      formObj: formJs.formObj, //基本信息
      handleObj: formJs.handleObjs, //闭合申请单
      handleObjs1: formJs.handleObjs1,
      processObj: formJs.processObjs, //一级审核
      processObj1: formJs.processObjs1, //一级审核
      examineObjs: formJs.examineObjs, //二级审核
      examineObjs1: formJs.examineObjs1, //二级审核
      activeNames: ["0"],
      handNum: false, //闭合申请单
      firstNum: false, //一级审核
      secondNum: false, //二级审核
      handleData: {
        fCompanyid: "", // 施工标段id
        fId: "", // 申请单fid //为空判断为新增
        fParentid: "", // 对应的超标记录fid
        fWarningcontent: "", // 预警内容
        fReason: "", // 问题原因
        fHandleway: "", // 处理方式
        fHandleresult: "", // 处理结果
        fHandledate: "",
        fHandledates: "", // 处理日期
        fHandleusername: "", // 处理人名称
        fHandlefile: "", // 处理附件id
        fFirstcheckresult: "", // 一级审核处理结果
        fFirstcheckopinion: "", // 一级审核处理意见
        fFirstcheckusername: "", // 一级审核处理人name
        fFirstcheckdates: "", // 一级审核处理日期
        fSecondcheckresult: "", // 二级审核处理结果
        fSecondcheckopinion: "", // 二级审核处理意见
        fSecondcheckusername: "", // 二级审核处理人name
        fSecondcheckdates: "", // 二级审核处理日期
        aduitStatus: null, //保存状态
        userId: "", // 当前登录人id
        userName: "", // 当前登录人姓名
        recordfiles: [], // 删除文件id集合
      },
      Sign: "",
      // supervisionUserList: [], //监理用户列表初始值
      // projectUsersList: [], //项目部列表初始值

      formData: formJs.formData,
      saveData: null,
      // 弹框

      userInfo: {}, //登录用户
    };
  },
  components: {
    TableData, //主页面列表
    Pagination, //分页
    publicForm, //表单
  },
  created() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
    console.log("userInfo", this.userInfo);
  },
  mounted() {
    this.getList = {
      fCompanyid: "", // 查询条件项目名称id
      page: 1, // 当前页码
      pageSize: 20, // 每页显示条数
      userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
      modelType: "0", // 0-待办 1-已办 传2 表示列表页查询
      fQualitygridtype: "", // 质量网格类别
      fQualitygridclass: "", // 上方查询条件质量网格
      keyWord: "", // 责任人
    };
    this.getHeight();
    this.getData();
    this.yj_searchForm(this.getList);
    this.btnRole(this.name);
    // this.getProjectUserList(this.userInfo.companyId);
    this.getSupervisionUser(this.userInfo.jlCompanyId);
    this.table_config.operation.cols = [
      {
        prop: "fStatus",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];
    this.table_config.operation["specialClass"] = function (rowData) {
      var color = null;
      if (rowData == "未提交") {
        color = "red !important";
      } else if (rowData == "已完成") {
        //  {
        //   color = "#409eff !important";
        // } else if (rowData == "运输中") {
        //   color = "#e6a23c  !important";
        // }
        color = "green !important";
      }
      return color;
    };
  },
  methods: {
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });

        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_view = btnStr.includes("yj_view");
        this.yj_export = btnStr.includes("yj_export");
      } else {
        this.yj_edit = true;
        this.yj_view = true;
        this.yj_export = true;
      }
    },

    modelType(e) {
      this.fId = "";
      this.row = "";
      if (e == "待办") {
        this.getList.modelType = "0";
        this.getList.userId = this.userInfo.userId;
      } else {
        this.getList.modelType = "1";
        this.getList.userId = this.userInfo.userId;
      }
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(id) {
      this.loading = true;
      getQualityDutyStationLists(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          console.log("列表");
          this.loading = false;
        });
    },

    edit(titel) {
      this.Sign = titel;
      if (titel == "编辑") {
        this.dialogTitle = "不合格报告处理";
        this.btnShow = true;
        if (this.fId != "" && this.fId != null) {
          // if (this.row.fStatus == "编辑中" || this.row.fStatus == "被退回") {
          this.loadingEditDialog = true; //弹框loading
          this.dialogEditVisible = true;
          this.getConcrete(this.fId);
          // } else {
          //   return this.$message.error("本条数据不可编辑");
          // }
        } else {
          return this.$message.error("请先选择需要编辑的数据");
        }
      } else {
        this.dialogTitle = "查看";
        this.btnShow = false;
      }
    },
    // 获取详情
    getConcrete(id) {
      getQualityDutyStationByFid({ fId: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.loadingEditDialog = false; //弹框loading
            this.formData = res.data.yjQmpMsQualitydutystationManagement;
            if (this.Sign == "编辑") {
              //填报人
              if (
                this.formData.fReportusername == "" ||
                this.formData.fReportusername == null ||
                this.formData.fReportuserid == "" ||
                this.formData.fReportuserid == null
              ) {
                this.formData.fReportusername = this.userInfo.realName;
                this.formData.fReportuserid = this.userInfo.userId;
              }
              //填报日期
              if (
                this.formData.fReportdates == "" ||
                this.formData.fReportdates == null
              ) {
                this.formData.fReportdates = this.timeYMD;
              }
            }
          } else {
            console.log("详情接口", res.errcode);
          }
        })
        .catch((err) => {
          console.log(err.msg);
        });
    },
    // 保存
    yj_saveForm(num) {
      this.fId = "";
      if (num == 0) {
        if (this.$refs.publicForm0.submitForm()) {
          if (this.$refs.publicForm1.submitForm()) {
            if (this.$refs.publicForm2.submitForm()) {
              this.saveData = {
                fId: this.formData.fId,
                userId: this.userInfo.userId,
                userName: this.userInfo.realName,
                fProjectname: this.formData.fProjectname,
                fProjectid: this.formData.fProjectid,
                fCompanyname: this.formData.fCompanyname,
                fCompanyid: this.formData.fCompanyid,

                fQualitygridtype: this.formData.fQualitygridtype, //工程网格类别
                fQualitygridclass: this.formData.fQualitygridclass, //质量网格类别
                fProjectposition: this.formData.fProjectposition, //工程部位

                fSgusername: this.formData.fSgusername, //施工负责人
                fSguserid: this.formData.fSguserid, //施工负责人id
                fSgusermobile: this.formData.fSgusermobile, //施工负责人电话

                fCheckusername: this.formData.fCheckusername, //现场质检员
                fCheckuserid: this.formData.fCheckuserid, //现场质检员id
                fCheckusermobile: this.formData.fCheckusermobile, //现场质检员电话

                fTestusername: this.formData.fTestusername, //试验员
                fTestuserid: this.formData.fTestuserid, //试验员id
                fTestusermobile: this.formData.fTestusermobile, //试验员电话

                fScenesupervisor: this.formData.fScenesupervisor, //驻地监理
                fScenesupervisorid: this.formData.fScenesupervisorid, //驻地监理id
                fScenesupervisormobile: this.formData.fScenesupervisormobile, //驻地监理电话

                fStationsupervisor: this.formData.fStationsupervisor, //现场监理员
                fStationsupervisorid: this.formData.fStationsupervisorid, //现场监理员id
                fStationsupervisormobile:
                  this.formData.fStationsupervisormobile, //现场监理员电话

                fTestsupervisor: this.formData.fTestsupervisor, //试验监理
                fTestsupervisorid: this.formData.fTestsupervisorid, //试验监理id
                fTestsupervisormobile: this.formData.fTestsupervisormobile, //试验监理电话

                fReportuserid: this.formData.fReportuserid, //填报人id
                fReportusername: this.formData.fReportusername, //填报人
                fReportdates: this.formData.fReportdates, //填报日期
                fSubmitengineerid: this.formData.fSubmitengineerid, //提交项目总工id
                fSubmitengineer: this.formData.fSubmitengineer, //提交项目总工
              };
              saveQualityDutyStation(this.saveData)
                .then((res) => {
                  if (res.errcode == 0) {
                    this.yj_searchForm(this.getList);
                    this.dialogEditVisible = false;
                    this.$message.success("新增成功");
                  } else {
                    this.$message.error(res.msg);
                    console.log("接口报错");
                  }
                })
                .catch((error) => {
                  console.log(error);
                });
            } else {
              console.log("error");
            }
          } else {
            console.log("error");
          }
        } else {
          console.log("error");
        }
      }
    },
    // 折叠面板
    changeCollapse(e) {
      console.log(this.activeNames, e);
    },
    // 获取页面容器高度
    getHeight() {
      var h = document.documentElement.clientHeight; //获取页面可见高度
      this.dialogHeight = h * 0.36 + "px";
    },
    // 点击查看
    yj_viewForm(row, label) {
      this.fId = row.fId;
      if (label == "报告编号") {
        this.editText(this.fId);
      }
    },

    // 查看
    editText(id) {
      this.dialogTitle = "查看";
      this.Sign = "查看";
      this.btnShow = false;
      if (id != "" && id != null) {
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        getQualityDutyStationByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              this.loadingEditDialog = false; //弹框loading
              this.formData = res.data.yjQmpMsQualitydutystationManagement;
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },
    // // 调人员
    // getProjectUserList(id) {
    //   this.projectUsersList = []; //项目部列表初始值
    //   var getProjectUserList = []; //监理用户列表过滤后
    //   getBaseDepartmentUser({ fCompanyid: id })
    //     .then((res) => {
    //       if (res.errcode == 0) {
    //         var getProjectUser = {
    //           value: "",
    //           label: "",
    //         };
    //         res.data.childList.map((v) => {
    //           if (v.personList != undefined) {
    //             v.personList.map((item) => {
    //               this.projectUsersList.push(item);
    //             });
    //           }
    //         });

    //         this.projectUsersList.map((item) => {
    //           getProjectUser = {
    //             value: item.fRealname,
    //             label: item.fRealname,
    //           };
    //           getProjectUserList.push(getProjectUser);
    //         });
    //         // console.log("项目部", getProjectUserList);
    //         this.project[0].options = getProjectUserList;
    //         this.project[2].options = getProjectUserList;
    //         this.project[4].options = getProjectUserList;
    //         this.project[7].options = getProjectUserList;
    //       } else {
    //         this.$message.error(res.msg);
    //         console.log("部门管理-查询部门列表以及下属人员,接口报错");
    //       }
    //     })
    //     .catch((error) => {
    //       console.log("部门管理-查询部门列表以及下属人员", error.msg);
    //     });
    // },
    // getSupervisionUser(id) {
    //   this.supervisionUserList = []; //监理用户列表初始值
    //   var getSupervisionUserList = []; //监理用户列表过滤后
    //   getBaseDepartmentUser({ fCompanyid: id })
    //     .then((res) => {
    //       if (res.errcode == 0) {
    //         var getSupervisionUser = {
    //           value: "",
    //           label: "",
    //         };

    //         res.data.childList.map((v) => {
    //           if (v.personList != undefined) {
    //             v.personList.map((item) => {
    //               this.supervisionUserList.push(item);
    //             });
    //           }
    //         });

    //         this.supervisionUserList.map((item) => {
    //           getSupervisionUser = {
    //             value: item.fRealname,
    //             label: item.fRealname,
    //           };
    //           getSupervisionUserList.push(getSupervisionUser);
    //         });
    //         // console.log("监理", getSupervisionUserList);
    //         this.supervision[0].options = getSupervisionUserList;
    //         this.supervision[2].options = getSupervisionUserList;
    //         this.supervision[4].options = getSupervisionUserList;
    //       } else {
    //         this.$message.error(res.msg);
    //         console.log("部门管理-查询部门列表以及下属人员,接口报错");
    //       }
    //     })
    //     .catch((error) => {
    //       console.log("部门管理-查询部门列表以及下属人员", error.msg);
    //     });
    // },
    // // 调人员
    selectChange(value, index, prop) {
      console.log("下拉变", value, index, prop);
    },
    inputChange(value, index, prop) {
      console.log("input变", value, index, prop);
    },
    inputFocus(index, prop) {
      console.log("input获焦", index, prop);
    },
    getData() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      this.timeYMD = `${y}-${m}-${d}`;
    },
    // 点击当前
    rowChange(val) {
      this.row = val;
      this.fId = val.fId;
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>

<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}
/* 弹框 */

/* .mouldForm /deep/ .el-col-12 .el-form-item:first-child .el-input__suffix {
  left: 84% !important;
} */
.publicForm .mouldForm /deep/ .el-form-item__content {
  margin-left: 105px !important;
}
/* 弹框 */
</style>